package todolist.test;

import todolist.activities.RegisterActivity;
import android.graphics.Rect;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class JUnitRegisterScreenButton extends ActivityInstrumentationTestCase2<RegisterActivity> {

	private RegisterActivity mActivity;
	private Button registerButton, cancelButton;
	private View mainLayout;

	public JUnitRegisterScreenButton() {
		super("todolist.activities", RegisterActivity.class);
	}

	// start activity, gets button and view.
	protected void setUp() throws Exception {
		super.setUp();
		mActivity = this.getActivity();  
		registerButton = (Button) mActivity.findViewById(todolist.activities.R.id.btnRegister);
		cancelButton = (Button) mActivity.findViewById(todolist.activities.R.id.cancelButton);
		mainLayout = (View) mActivity.findViewById(todolist.activities.R.id.registerlayout); 
	}

	// tests that button will be put on the screen
	public void testAddButtonOnScreen() {  
		//this determines the current visible screen size
		int fullWidth = mainLayout.getWidth();  
		int fullHeight = mainLayout.getHeight();  
		int[] mainLayoutLocation = new int[2];  
		mainLayout.getLocationOnScreen(mainLayoutLocation);

		// Gets the location of the button
		int[] viewLocation = new int[2];  
		registerButton.getLocationOnScreen(viewLocation);  

		Rect outRect = new Rect();  
		registerButton.getDrawingRect(outRect);  

		// makes sure button isnt off the screen horizontally
		assertTrue("Add button off the right of the screen", fullWidth  
				+ mainLayoutLocation[0] > outRect.width() + viewLocation[0]);  

		// makes sure the button isnt off the screen vertically
		assertTrue("Add button off the bottom of the screen", fullHeight  
				+ mainLayoutLocation[1] > outRect.height() + viewLocation[1]);  
	}  



}

